<?php

/**
 * Base Cloud class
 *
 * PHP version 5
 *
 * @category   Web
 * @package    Data2People
 * @subpackage Models
 * @author     Mike Bevz <mike.bevz@data2people>
 * @copyright  2007-2008 (c) Mike Bevz
 * @license    The BSD License http://data2people.com/license.txt
 * @version    SVN: $Id: BaseCloud.php 14 2008-12-01 23:02:54Z michael.bevz $
 *
 *
 */

require_once 'Doctrine/Record.php';
require_once 'TimestampListener.php';

abstract class BaseCloud extends Doctrine_Record
{
    /**
    * Sets table definitions
    *
    * @return void
    */
    public function setTableDefinition()
    {
        $this->setTableName('clouds');
        $this->hasColumn('id', 'integer', 4, array('primary' => true,
                                                   'autoincrement' => true,
                                                   'unsigned' => true));
        $this->hasColumn('content', 'string', 255);
        $this->hasColumn('frequency', 'int', 4);
        $this->hasColumn('occur', 'int', 4);
        $this->hasColumn('pubdate', 'timestamp', array('format'=> 'Y-m-d H:i:s'));
        $this->hasColumn('tag_id', 'int', 4, array('unsigned' => true));
        $this->hasColumn('views', 'integer', 4);
        
    }
    
   /**
    * Sets up relations
    *
    * @return void
    */
    public function setUp()
    {
        /*$this->hasMany('Word', array('local' => 'news_id',
                                           'foreign' => 'word_id',
                                           'refClass' => 'WordRefNews'));
        
        $this->hasMany('Phrase', array('local' => 'news_id',
                                         'foreign' => 'phrase_id',
                                         'refClass' => 'PhraseRefNews'));*/
        

        
        $this->actAs('Timestampable',
               array('created_at' =>  array('name'  =>  'created_at',
                                            'type'    =>  'timestamp',
                                            'format'  =>  'Y-m-d H:i:s',
                                            'disabled' => false,
                                            'options' =>  array()),
                     'updated_at' =>  array('name'  =>  'updated_at',
                                            'type'    =>  'timestamp',
                                            'format'  =>  'Y-m-d H:i:s',
                                            'disabled' => false,
                                            'options' =>  array())));
        
       
        $this->setListener(new TimestampListener());
    }
    
    /**
     * Llink is unique identifier so we cancel insert if the link exists
     *
     * @param unknown_type $event
     */
    /*public function preSave(Doctrine_Event $event)
    {
        $clouditem = new Cloud();
        $clouds     = $clouditem->get($this->link);
        if (count($clouds) > 0) {
            $event->skipOperation();
        }
    }*/

}